$(function () {
  //首页图标
  $.ajax({ url: "http://chst.vip:1234/api/getindexmenu" }).then((res) => {
    let htm = "";
    let regExp = /images\/\w{1,}\.png/;
    $.each(res.result, (i, item) => {
      let img = regExp.exec(item.img);
      htm += `
          <div class="col">
            <a href="pages/${item.titlehref}">
                <img src='http://chst.vip:8081/for-stu/wfzh/${img}'>
                <p class="in_name">
                ${item.name}
                </p>
            </a>
          </div>
            `;
    });

    $("nav .container .row").html(htm);
    //首页 《更多》 折叠动画
    $("#info")
      .find(".col:eq(7)")
      .click(function (event) {
        event.preventDefault();
        $(this).nextAll().slideToggle(200);
      });
  });

  //首页商品列表
  $.ajax({ url: "http://chst.vip:1234/api/getmoneyctrl" }).then((res) => {
    let htm = "";
    let regExp = /(?<=imgurl=)[^'"]*/;
    $.each(res.result, (i, item) => {
      let productImg2 = regExp.exec(item.productImg2);
      htm += `
              <li>
                <a href="./pages/indexXiang.html?productid=${item.productId}" class="clearfix">
                  <div class="img fl">
                    <img src=${productImg2[0]} height='100' width='100' alt=''>
                  </div>
                  <div class="infoR">
                    <div class="title">
                      <h4>${item.productName}<br>
                      <span>${item.productPinkage}</span>
                      </h4>
                    </div>
                    <div class="other">
                      <span class="mall fl">${item.productFrom} | ${item.productTime}</span>
                      <em class="fr">
                          <i class="iconfont icon-xiaoxi "></i>
                          <span>${item.productComCount}</span>
                      </em>
                    </div>
                  </div>
                </a>
              </li>
              `;
    });
    $("#product .info").html(htm);
  });
});
